/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:马星俊
 */

import React, {FC} from 'react';
import {Card, Descriptions, Drawer, Spin, Tabs} from 'antd';
import styles from '@/utils/utils.less'
import {SysDeptModel} from '../data';
import HistoryLogTable from '@/components/HistoryLog';
import Member from "@/pages/sys/dept/components/Member";
import {DetailsDialogProps} from "@/global";
import service from "../service";
import useLoad from "@/hooks/useLoad";
import StatusTag from "@/components/StatusTag";

const {TabPane} = Tabs;

/** 系统机构详情组件 */
const SysDeptDetails: FC<DetailsDialogProps> = (props) => {
  const {params: {id}, visible, hide} = props;
  const {loading, data: model} = useLoad<SysDeptModel>({
    isLoad: Boolean(id),
    onLoad: () => service.selectById(id)
  }, [id]);

  return (
    <Drawer
      title="查看系统机构详细信息"
      width="50%"
      visible={visible}
      onClose={hide}
      destroyOnClose
      className={styles.drawerBodyPadding}>
      <Spin spinning={loading} wrapperClassName={styles.h100p}>
        <Tabs className={styles.drawerBodyTabsPadding}>
          <TabPane tab="基本信息" key="basic">
            {model && (
              <Card bordered={false} className={styles.cardBodyDesc}>
                <Descriptions column={1} bordered={true} size="small" className={styles.detailsDescriptions}>
                  <Descriptions.Item label="机构主键">{model.id}</Descriptions.Item>
                  <Descriptions.Item label="上级主键">{model.parentId}</Descriptions.Item>
                  <Descriptions.Item label="机构名称">{model.name}</Descriptions.Item>
                  <Descriptions.Item label="机构编码">{model.code}</Descriptions.Item>
                  <Descriptions.Item label="机构类型">{model.category}</Descriptions.Item>
                  <Descriptions.Item label="机构性质">{model.nature}</Descriptions.Item>
                  <Descriptions.Item label="负责人">{model.leaderName}</Descriptions.Item>
                  <Descriptions.Item label="状态">
                    <StatusTag status={model.status} trueLable="启用" falseLable="禁用"/>
                  </Descriptions.Item>
                  <Descriptions.Item label="备注">{model.remark}</Descriptions.Item>
                </Descriptions>
              </Card>
            )}
          </TabPane>
          <TabPane tab="部门成员" key="member">
            {model && (<Member primaryKey={model.id}/>)}
          </TabPane>
          <TabPane tab="操作日志" key="history">
            {model && (<HistoryLogTable tableName="SysDept" primaryKey={model.id}/>)}
          </TabPane>
        </Tabs>
      </Spin>
    </Drawer>
  );
};

export default SysDeptDetails;
